﻿using System;
using System.Activities;
using System.ComponentModel;
using System.Collections.Generic;

namespace Vision.Core.ActivityComponents.Services
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class WebServiceInvokeMethod<T> : NativeActivity
    {        
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        [Category("Input")]
        public InArgument<string> MethodName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        [Category("Input")]
        public InArgument<object[]> MethodParams { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [DefaultValue(null)]
        [Category("Output")]
        public OutArgument<T> Result { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {            
            Components.DynamicWebService dynamicWebService = (Components.DynamicWebService)context.Properties.Find("9d40e1ff-4d19-46c1-a77e-348a229c6acc");
            if (dynamicWebService != null){
                this.Result.Set(context, dynamicWebService.InvokeMethod<T>(this.MethodName.Get(context), new List<object>(this.MethodParams.Get(context))));
            }
        }
    }
}
